﻿namespace common
{
    internal class MediaPlayer
    {
        public AxWMPLib.AxWindowsMediaPlayer[] axWindowsMediaPlayers;
        private string path;

        public MediaPlayer(string path, params AxWMPLib.AxWindowsMediaPlayer[] arr)
        {
            axWindowsMediaPlayers = arr;
            this.path = path;
        }

        /// <summary>
        /// 给具体的MediaPlayer控件设置声音文件
        /// </summary>
        /// <param name="index"></param>
        /// <param name="num"></param>
        public void GetSound(int index, int num)
        {
            axWindowsMediaPlayers[index].URL = path + num.ToString() + ".mp3";
            axWindowsMediaPlayers[index].Ctlcontrols.stop();
        }

        private string note;

        public string Note
        {
            get { return note; }
            set { note = value; }
        }

        //播放
        public void Play()
        {
            int index = 0;

            //停止原来播放的声音。相当于钢琴某个键按过后还在余音，此时再此按到此键，则原有余音结束
            axWindowsMediaPlayers[index].Ctlcontrols.stop();
            //播放
            axWindowsMediaPlayers[index].Ctlcontrols.play();
        }
    }
}